package com.eastidea.live.util;

import org.apache.commons.lang3.StringUtils;
import org.im4java.core.ConvertCmd;
import org.im4java.core.IMOperation;
import org.im4java.process.StandardStream;

public class ImageUtil extends StringUtils {

	public static String ScaleImage(String folder, String srcFilePath,
			String postfix, double height, double width) {

		String dectFilePath = srcFilePath.replace(".", postfix + ".");

		IMOperation op = new IMOperation();
		op.addImage();
		op.resize(Integer.valueOf((int) width), Integer.valueOf((int) height),
				"^");
		op.addImage();
		ConvertCmd convert = new ForWinConvertCmd();
		convert.setErrorConsumer(StandardStream.STDERR);
		try {
			convert.run(op, new Object[] { folder + srcFilePath,
					folder + dectFilePath });
		} catch (Exception e) {
			e.printStackTrace();
		}

		return dectFilePath;
	}
}
